package com.his.util.util;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

public class MapUtil {
    public static <T> T conversionMapToObj(Map map, Class<T> clazz) {
        try {
            Object obj = clazz.getConstructor().newInstance();
            map.forEach((k, v) -> {
                try {
                    Field field = obj.getClass().getDeclaredField((String) k);
                    field.setAccessible(true);
                    field.set(obj, v);
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            });

            return (T) obj;
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }

        return null;
    }
}
